package com.matt.foundation.vo.course;

import com.matt.foundation.constant.CourseConstant;
import com.matt.foundation.constant.CourseEarlyConstant;
import com.matt.foundation.utils.DateUtil;
import com.matt.foundation.vo.ChildrenCourseItemVo;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/1/8
 * *******************************
 */
@Data
public class WebCourseItemListVo {

    private String planId;

    private Date courseDate;

    private String beginTime;

    private String endTime;

    private String teachingAreaName;

    private String teacherId;

    private String teacherName;

    private String teachingAreaId;

    private String earlyTitle;

    private int earlyWeek = 0;

    private int courseType = 0;

    private String courseTypeName;

    private boolean chosen = false;

    private List<String> childrenNames;

    public static WebCourseItemListVo of(WebCourseListVo listVo, List<ChildrenCourseItemVo> doingList, String courseTypeName) {
        WebCourseItemListVo vo = new WebCourseItemListVo();
        vo.setPlanId(listVo.getPlanId());
        vo.setCourseDate(listVo.getCourseDate());
        vo.setBeginTime(listVo.getBeginTime());
        vo.setEndTime(listVo.getEndTime());
        vo.setTeachingAreaName(listVo.getTeachingAreaName());
        vo.setTeacherId(listVo.getTeacherId());
        vo.setTeacherName(listVo.getTeacherName());
        vo.setTeachingAreaId(listVo.getTeachingAreaId());
        vo.setEarlyTitle(listVo.getEarlyTitle());
        vo.setEarlyWeek(listVo.getEarlyWeek());
        Integer courseType = listVo.getCourseType();
        vo.setCourseType(courseType);
        if (CourseConstant.CourseType.SAT.codeOf() == courseType)
            vo.setCourseTypeName("SAT早教");
        if (CourseConstant.CourseType.AREA_BUILD.codeOf() == courseType)
            vo.setCourseTypeName(courseTypeName);
        if (CourseConstant.CourseType.PUBLIC.codeOf() == courseType)
            vo.setCourseTypeName(courseTypeName);

        vo.setChildrenNames(listVo.getChildrenNames());
        vo.setChosen(contains(doingList, listVo));
        return vo;
    }

    public static boolean contains(List<ChildrenCourseItemVo> doingList, WebCourseListVo listVo){
        return doingList.stream().anyMatch(o -> listVo.getPlanId().equals(o.getPlanId()));
    }
}
